package com.etl.dataflow.scheduler.admin.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class InsertUpdateHandler implements MetaObjectHandler {

    /**
     * 插入记录时调用
     *
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "idt", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "udt", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "creatorId", Long.class, 1234L);
    }

    /**
     * 更新记录时调用
     *
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "udt", LocalDateTime.class, LocalDateTime.now());
    }
}
